<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <title>订单列表页</title>
    <link rel="stylesheet" th:href="@{~/pc/layui/css/layui.css}" media="all">
    <style>
        body{margin: 10px;}
        .demo-carousel{height: 200px; line-height: 200px; text-align: center;}
    </style>
</head>
<body>

<table class="layui-hide" id="test" lay-filter="demo"></table>

<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>


</div>


<!-- jQuery 3 -->
<script th:src="@{~/pc/js/jquery.min.js}"></script>
<script th:src="@{~/pc/layui/layui.js}"></script>
<script>

    layui.use(['laypage', 'layer', 'table', 'element'], function(){
        var laypage = layui.laypage //分页
            ,layer = layui.layer //弹层
            ,table = layui.table //表格
            ,element = layui.element; //元素操作


        //监听Tab切换
        element.on('tab(demo)', function(data){
            layer.msg('切换了：'+ this.innerHTML);
            console.log(data);
        });

        //执行一个 table 实例
        table.render({
            elem: '#test'
            ,height: 332
            ,url: '/pc/record' //数据接口
            ,page: true //开启分页
            ,cols: //表头
                [
                    [
                        {field: 'id', title: 'ID', sort: true, fixed: 'left'}
                        ,{field: 'area', title: '区域', width:80}
                        ,{field: 'floor', title: '楼层', width:80, sort: true}
                        ,{field: 'room', title: '房间', width:80}
                        ,{field: 'detail', title: '维修详情', width: 120}
                        ,{field: 'wechatOpenid', title: '用户微信ID', width: 120, sort: true}
                        ,{field: 'registrantName', title: '真实姓名', width: 120, sort: true}
                        ,{field: 'equipmentId', title: '仪器编号', width: 120}
                        ,{field: 'equipmentName', title: '仪器名称', width: 120, sort: true}
                        ,{field: 'registrantNumber', title: '学号', width: 80}
                        ,{field: 'photoStatus', title: '是否上传图片', width: 140, sort: true}
                        ,{field: 'classify', title: '故障类型', width: 120, sort: true}
                        ,{field: 'repairStatus', title: '维修状态', width: 120}
                        ,{field: 'deleteStatus', title: '是否有效', width: 120, sort: true}
                        ,{field: 'createTime', title: '创建时间', width: 120, sort: true}
                        ,{field: 'updateTime', title: '更新时间', width: 120, sort: true}
                        ,{fixed: 'right', width: 120, align:'center', toolbar: '#barDemo'}
                    ]
                ]
        });

        //监听工具条
        table.on('tool(demo)', function(obj){ //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
            var data = obj.data //获得当前行数据
                ,layEvent = obj.event; //获得 lay-event 对应的值
            var id = data.id;
            if(layEvent === 'detail'){
                layer.msg('查看操作');
            } else if(layEvent === 'del'){
                console.log("data:" + data);

                layer.confirm('真的删除行么', function(index){
                    obj.del(); //删除对应行（tr）的DOM结构
                    layer.close(index);
                    //向服务端发送删除指令
                    $.get('/pc/record/' + id);

                });
            } else if(layEvent === 'edit'){
                layer.msg('编辑操作');
            }
        });


        //分页
        laypage.render({
            elem: 'pageDemo' //分页容器的id
            ,count: 100 //总页数
            ,skin: '#1E9FFF' //自定义选中色值
            //,skip: true //开启跳页
            ,jump: function(obj, first){
                if(!first){
                    layer.msg('第'+ obj.curr +'页');
                }
            }
        });

    });
</script>
</body>
</html>
